home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / programming / gcc / gcc2.7.0 / gcc270cp.lha / gnu / lib / g++-include / std / stdexcept.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  3.6 KB  |  124 lines

  1. // Methods for Exception Support for -*- C++ -*-
  2. // Copyright (C) 1994, 1995 Free Software Foundation
  3.  
  4. // This file is part of the GNU ANSI C++ Library.  This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 2, or (at your option)
  8. // any later version.
  9.  
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this library; see the file COPYING.  If not, write to the Free
  17. // Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // As a special exception, if you link this library with files
  20. // compiled with a GNU compiler to produce an executable, this does not cause
  21. // the resulting executable to be covered by the GNU General Public License.
  22. // This exception does not however invalidate any other reasons why
  23. // the executable file might be covered by the GNU General Public License.
  24.  
  25. // Written by Mike Stump based upon the specification in the 20 September 1994
  26. // C++ working paper, ANSI document X3J16/94-0158.
  27.  
  28. #ifndef __STDEXCEPT__
  29. #define __STDEXCEPT__
  30.  
  31. #ifdef __GNUG__
  32. #pragma interface "std/stdexcept.h"
  33. #endif
  34.  
  35. #include <typeinfo>
  36.  
  37. #if 0
  38. #include <string>
  39. typedef string __string;
  40. #else
  41. typedef const char * __string;
  42. #endif
  43.  
  44. class exception {
  45. public:
  46.   typedef void (*raise_handler)(exception&);
  47.   static raise_handler set_raise_handler(raise_handler handler_arg);
  48.   exception (const __string& what_arg): desc (what_arg) { }
  49.   virtual ~exception() { }
  50.   void raise();
  51.   virtual __string what() const { return desc; }
  52. protected:
  53.   exception() { }
  54.   virtual void do_raise() { }
  55. private:
  56.   __string desc;
  57. };
  58.  
  59. class logic_error : public exception {
  60. public:
  61.   logic_error(const __string& what_arg): exception (what_arg) { }
  62.   virtual ~logic_error() { }
  63. };
  64.  
  65. class domain_error : public logic_error {
  66. public:
  67.   domain_error (const __string& what_arg): logic_error (what_arg) { }
  68.   virtual ~domain_error () { }
  69. };
  70.  
  71. class invalid_argument : public logic_error {
  72. public:
  73.   invalid_argument (const __string& what_arg): logic_error (what_arg) { }
  74.   virtual ~invalid_argument () { }
  75. };
  76.  
  77. class length_error : public logic_error {
  78. public:
  79.   length_error (const __string& what_arg): logic_error (what_arg) { }
  80.   virtual ~length_error () { }
  81. };
  82.  
  83. class out_of_range : public logic_error {
  84. public:
  85.   out_of_range (const __string& what_arg): logic_error (what_arg) { }
  86.   virtual ~out_of_range () { }
  87. };
  88.  
  89. class runtime_error : public exception {
  90. public:
  91.   runtime_error(const __string& what_arg): exception (what_arg) { }
  92.   virtual ~runtime_error() { }
  93. protected:
  94.   runtime_error(): exception () { }
  95. };
  96.  
  97. class range_error : public runtime_error {
  98. public:
  99.   range_error (const __string& what_arg): runtime_error (what_arg) { }
  100.   virtual ~range_error () { }
  101. };
  102.  
  103. class overflow_error : public runtime_error {
  104. public:
  105.   overflow_error (const __string& what_arg): runtime_error (what_arg) { }
  106.   virtual ~overflow_error () { }
  107. };
  108.  
  109. // These are moved here from typeinfo so that we can compile with -frtti
  110. class bad_cast : public logic_error {
  111. public:
  112.   bad_cast(const __string& what_arg): logic_error (what_arg) { }
  113.   virtual ~bad_cast() { }
  114. };
  115.  
  116. extern bad_cast __bad_cast_object;
  117.  
  118. class bad_typeid : public logic_error {
  119.  public:
  120.   bad_typeid (): logic_error ("bad_typeid") { }
  121.   virtual ~bad_typeid () { }
  122. };
  123. #endif
  124.